package pieces;

import java.util.ArrayList;

import players.Player;

import model.*;

public class Pawn extends MoveDependent
{
	public Pawn(Location loc, GridGame<Piece> grid, int color)
	{
		super(loc, grid, PAWN, color);
	}
	@Override
	public ArrayList<Location> getMoveLocations()
	{
		ArrayList<Location> locs = new ArrayList<Location>();
		ArrayList<Location> threatLocs = getThreateningLocations();
		int directionInFront;
		if (getColor() == Player.WHITE)
			directionInFront = Location.NORTH;
		else
			directionInFront = Location.SOUTH;
		Location inFront = getLocationInDirection(directionInFront);
		Location twoInFront = inFront.getAdjacentLocation(directionInFront);
		if (inFront != null && grid.inBounds(inFront) && grid.getObjectAt(inFront) == null)
		{
			locs.add(inFront);
			if (twoInFront != null && grid.inBounds(twoInFront) && grid.getObjectAt(twoInFront) == null && !hasMoved())
				locs.add(twoInFront);
		}
		
		for(Location threatLoc : threatLocs)
			if(grid.getObjectAt(threatLoc) != null)
				locs.add(threatLoc);
		return locs;
	}
	public ArrayList<Location> getThreateningLocations()
	{
		ArrayList<Location> threatening = new ArrayList<Location>(2);
		int diagonal1, diagonal2;
		if (getColor() == Player.WHITE)
		{
			diagonal1 = Location.NORTHEAST;
			diagonal2 = Location.NORTHWEST;
		}
		else
		{
			diagonal1 = Location.SOUTHEAST;
			diagonal2 = Location.SOUTHWEST;
		}
		Location threaten1 = getLocationInDirection(diagonal1);
		Location threaten2 = getLocationInDirection(diagonal2);
		if (threaten1 != null && grid.inBounds(threaten1))
				threatening.add(threaten1);
		if (threaten2 != null && grid.inBounds(threaten2))
				threatening.add(threaten2);
		return threatening;
	}
	@Override
	public int getValue()
	{
		return PAWN_VALUE;
	}
}
